package com.imon.web.codesphere.data;

import org.apache.commons.io.FilenameUtils;
import org.bson.types.ObjectId;
import org.codehaus.jackson.annotate.JsonProperty;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

@Entity
public class FileSource {

	@Id
	private ObjectId Id;

	private String fileUrl;

	private Long revision = -1L;

	private String sourceCode;

	public String getFileUrl() {
		return fileUrl;
	}

	public void setFileUrl(final String aFileUrlRevision) {
		this.fileUrl = aFileUrlRevision;
	}

	public void setRevision(final Long aRevision) {
		this.revision = aRevision;
	}

	public Long getRevision() {
		return revision;
	}

	public void setSourceCode(final String aSourceCode) {
		this.sourceCode = aSourceCode;
	}

	public String getSourceCode() {
		return sourceCode;
	}

	@JsonProperty
	public String getFormat() {
		return FilenameUtils.getExtension(this.fileUrl);
	}

	@Override
	public String toString() {
		return "FileSource [Id=" + Id + ", fileUrl=" + fileUrl + ", revision=" + revision + ", sourceCode="
				+ sourceCode.length() + "]";
	}
}
